<%--<%@ page contentType='text/html; charset=UTF-8' %>--%>
<%@ page import='java.sql.ResultSet' %>
<%@ page import='forum.*' %>
<%@taglib uri="/WEB-INF/tlds/label.tld" prefix="lutag" %>

<% String sessionUsername = (String)session.getAttribute("username"); %>
<% String sessionType = (String)session.getAttribute("type"); %>

<% String forum_id = request.getParameter("forum_id"); %>
<% String reqThread_id = request.getParameter("thread_id"); %>
<% String start = request.getParameter("start"); %>
      				
<% Utilities.addView(forum_id,reqThread_id); %>
<%@ page import='forum.*' %>
<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0 Transitional//EN\">

<html>
<head>
<title><lutag:label name="readmsg"/></title>
<link rel="stylesheet" href="./css/forum.css" type="text/css">
      <meta http-equiv="content-type" content="text/html; charset=utf-8">
      <script src="../editor/kindeditor.js"></script>
      <script>
        KE.show({
                id : 'myarea'
        });
	  </script>
</head>
<jsp:include page="./include/body.jsp" flush="true" />

	<table width="100%" height="20" border="0" cellpadding="1" cellspacing="1">
		<tr> 
			<td height="20" valign="top" class="pathBar">
				<a href="index.jsp" class="pathBarLink"><%= Variable.getForumName() %></a><span class="pathBarSeperator"> > </span>
				<a href="./index.jsp?page=thread&forum_id=<%= forum_id %>" class="pathBarLink"><%= Utilities.getforumTile(forum_id) %></a><span class="pathBarSeperator"> > </span>
				<a href="./index.jsp?page=message&forum_id=<%= forum_id %>&thread_id=<%=reqThread_id%>&start=<%= start %>" class="pathBarLink"><%= Utilities.getThreadTile(forum_id,reqThread_id) %></a>
			</td>
			<TD align="right" class="pathBar">
				<%= Utilities.getMorePages(Utilities.getReplies(forum_id,reqThread_id),forum_id,reqThread_id,false) %>
			</TD>
		</tr>
	</table>
	<table cellspacing="0" cellpadding="0" width="100%" class="table_bg" border="0" align="center">
<tr>
<td>
<table cellspacing="1" cellpadding="4" width="100%" border="0">
<tr class="tr_bg">            

	<%					
	DBConnectie db = new DBConnectie(Variable.getDb(),Variable.getDbLogin(),Variable.getDbPassword());

	db.connect();
						
	String thread_id = "null";
	String lastReply_id = "null";

	ResultSet rs = db.selectQuery(
		"SELECT * FROM forum_message " +
		"WHERE forum_id=\"" + forum_id + "\" AND thread_id =\"" + reqThread_id + "\" ORDER BY reply_id LIMIT "+ start + "," + Variable.getMessagePerPage());
							
		while(rs.next()){
			thread_id = rs.getString("thread_id");
			String reply_id = rs.getString("reply_id");
			String message = rs.getString("message");
			String user = rs.getString("user");
			String date_time = rs.getString("date_time");
	%>						
<tr class="table_bg">
	<% String titleAdmin = " " + date_time + "&nbsp;&nbsp;&nbsp;<a href=\"./index.jsp?page=editmessage&forum_id=" + forum_id + "&thread_id=" + thread_id + "&reply_id=" + reply_id + "&start=" + start + "\">Edit</a>&nbsp;&nbsp;&nbsp;<a href=\"../servlet/Reply.delete?forum_id=" + forum_id + "&thread_id=" + thread_id + "&reply_id=" + reply_id + "&start=" + start + "\">Delete</a>"; %>
	<% String titleUser = " " + date_time + "&nbsp;&nbsp;&nbsp;<a href=\"./index.jsp?page=editmessage&forum_id=" + forum_id + "&thread_id=" + thread_id + "&reply_id=" + reply_id + "&start=" + start + "\">Edit</a>"; %>
	<% String titleOther = " " + date_time; %>
	<% if(sessionType.equals("Admin")){ %>
        <td align="middle" colspan="2" class="tr_bg">
<span class="span_style">
<b><lutag:label name="postedon"/><lutag:label name="colon"/><%= titleAdmin %></b>
</span>
</td>
	<% }else{ %>
		<% if(sessionUsername.equals(user)){ %>
         <td align="middle" colspan="2" class="tr_bg">
<span class="span_style">
<b><lutag:label name="postedon"/><lutag:label name="colon"/><%= titleUser %></b>
</span>
</td>
		<% }else{ %>
         <td align="middle" colspan="2" class="tr_bg">
<span class="span_style">
<b><lutag:label name="postedon"/><lutag:label name="colon"/><%= titleOther %></b>
</span>
</td>
		<% } %>
	<% } %>		
		<tr bgcolor="#ffffff">
	<%    	
								
		ResultSet rs2 = db.selectQuery(
			"SELECT * FROM forum_users WHERE user_name =\"" + user + "\"");
			
		String group = null;
		String avatar = null;
		String member_title = null;
		String signature = null;	
		while(rs2.next()){
			group = rs2.getString("type");
			avatar = rs2.getString("avatar");
			member_title = rs2.getString("member_title");
			signature = rs2.getString("signature");
		}
						
		ResultSet rs3 = db.selectQuery(
			"SELECT count(*) count FROM forum_message WHERE user =\"" + user + "\"");
		
		while(rs3.next()){
			String messageCount = rs3.getString("count");
									
			if(avatar == null){
				avatar = "<br>";
			}else{
				avatar = "<img src=\"" + avatar + "\" width=\"65\" height=\"65\"><br>";								
			}						
			if(member_title == null){
				member_title = "";
			}else{
				member_title = member_title + "<br>";
			}						
			if(signature == null){
				signature = "";
			}else{
				signature =	"<br><br>--------<br>" + signature;
			}
	%>									
	<td align="left" valign="top" width="100">
<span class="span_style">
			<b><%= user.toUpperCase() %></b>
			<br>
			<%= member_title %>
			<%= avatar %><br>
			<lutag:label name="group"/><lutag:label name="colon"/><%= group %><br>
			<lutag:label name="posts"/><lutag:label name="colon"/><%= messageCount %><br>
		<% } %>
    
		<td align="left" valign="top" width="400">
<span class="span_style">
		<%= message %><%= signature %>
		</span>
</td>
</tr>
							
		<% lastReply_id = reply_id;
		}
		db.close();
		%>
	<tr class="table_bg">
    <%--分页--%>
	<% String back1 = "<a href=\"./index.jsp?page=thread&forum_id=" + forum_id + "\">";
	 String back2 = "</a> " + Utilities.getMorePages(Utilities.getReplies(forum_id,thread_id),forum_id,thread_id,false); 
	 %>

        <td align="right" colspan="2" class="tr_bg">
<span class="span_style">
<b><%=back1%><lutag:label name="back"/><%=back2%></b>
</span>
</td>
</table>
</td>
</tr>
</table>
	<br>
<table cellspacing="0" cellpadding="0" width="100%" class="table_bg" border="0" align="center">
<tr>
<td>
<table cellspacing="1" cellpadding="4" width="100%" border="0">
<tr class="tr_bg">
    <td align="left" colspan="3" class="tr_bg">
<span class="span_style">
<b><lutag:label name="addreply"/></b>
</span>
</td>
</tr>
		<tr bgcolor="#ffffff">
    <td align="left" valign="top" width="200">
<span class="span_style">
	<form action="../servlet/Reply.add" method="POST" name="formmessage">
	<input type="hidden" name="forum_id" value="<%= forum_id %>">
	<input type="hidden" name="thread_id" value="<%= thread_id %>">
	<input type="hidden" name="lastReply_id" value="<%= lastReply_id %>">
	<input type="hidden" name="user" value="<%= sessionUsername %>">
	<input type="hidden" name="start" value="<%= start %>">
	<lutag:label name="rpy"/>
	<textarea name="message" id="myarea" cols="100" rows="10" style="width:700px;height:300px;"></textarea>
	<input type="submit" value='<lutag:label name="submit"/>'>
	</form>
	</span>
</td>
</tr>
</table>
</td>
</tr>
</table>      

<jsp:include page="./include/footer.jsp" flush="true" />  
         
